package uk.org.landeg.euler.problems;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;

public class Problem002 extends AbstractProblem {
	public static void main(String[] args) {
		ProblemLauncher launcher = new ProblemLauncher(new Problem002());
		launcher.solve();
	}
	@Override
	public String getDescription() {
		return "By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.";
	}

	@Override
	public Integer getProblemNumber() {
		return 2;
	}

	@Override
	public Object solve() {
		notes.add("Use form of sequence : 1 2* 3 5 8* 13 ....");
		double goldenRatio = (1 + Math.sqrt(5))/2;
		double goldenRatioCubed = goldenRatio * goldenRatio * goldenRatio;
		
		notes.add("Golden ratio is (1 + sqrt(5))/2 = " + goldenRatio);
		notes.add("Even terms appear one in 3 terms : " + goldenRatioCubed);
		long fNumber = 2;
		long total = 0;
		StringBuilder terms = new StringBuilder("Using numbers : ");
		do {
			terms.append(fNumber + ", ");
			total += fNumber;
			fNumber = (long)(fNumber * goldenRatioCubed + 0.5);
		} while (fNumber < 4E6);
		notes.add(terms.toString());
		return total;
	}

}
